Skip to content

Conversation

ruslan-18
Copy link

@ruslan-18 ruslan-18 commented Jul 1, 2025

Description

relates to #1234

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see examples/ directory)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Acceptance tests got implemented or updated (see e.g. here)
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

Copy link

github-actions bot commented Jul 9, 2025

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Jul 9, 2025
@rubenhoenle rubenhoenle removed the Stale PR is marked as stale due to inactivity. label Jul 10, 2025
panic("implement me")
}

func toCreatePayload(model *Model) (*kms.CreateKeyRingPayload, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider implementing a unit test for this func.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added unit test

}, nil
}

func mapFields(keyRing *kms.KeyRing, model *Model) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added unit test

return &keyRingResource{}
}

type keyRingResource struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know if you are aware of this, please don't forget to implement the import.

You can ensure this by adding the code below:

// Ensure the implementation satisfies the expected interfaces.
var (
	_ resource.Resource                 = &keyRingResource{}
	_ resource.ResourceWithConfigure    = &keyRingResource{}
	_ resource.ResourceWithImportState  = &keyRingResource{}
)

See the git instance resource how to do it:

// Ensure the implementation satisfies the expected interfaces.
var (
_ resource.Resource = &gitResource{}
_ resource.ResourceWithConfigure = &gitResource{}
_ resource.ResourceWithImportState = &gitResource{}
)

Consider doing the same for the datasource, see the git instance datasource for example:

https://github.com/stackitcloud/terraform-provider-stackit/blob/main/stackit/internal/services/git/instance/datasource.go#L24-L27

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

func (k *keyRingResource) Metadata(ctx context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) {
response.TypeName = request.ProviderTypeName + "kms_key_ring"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
response.TypeName = request.ProviderTypeName + "kms_key_ring"
response.TypeName = request.ProviderTypeName + "_kms_key_ring"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

KeyRingId types.String `tfsdk:"key_ring_id"`
Id types.String `tfsdk:"id"` // needed by TF
ProjectId types.String `tfsdk:"project_id"`
RegionId types.String `tfsdk:"region_id"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RegionId types.String `tfsdk:"region_id"`
Region types.String `tfsdk:"region"` # small adjustment to stick with the naming conventions across the codebase

According to https://docs.api.stackit.cloud/documentation/kms/version/v1beta , the KMS API already uses the new multi-region concept.

See e.g. the stackit_routing_table resource how to implement the multi-region concept. The resource has a region field which is marked as optional and will use the default_region configured in the provider as a fallback: https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/resources/routing_table

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated region logic

if providerData.KMSCustomEndpoint != "" {
apiClientConfigOptions = append(apiClientConfigOptions, config.WithEndpoint(providerData.KMSCustomEndpoint))
} else {
apiClientConfigOptions = append(apiClientConfigOptions, config.WithRegion(providerData.GetRegion()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
apiClientConfigOptions = append(apiClientConfigOptions, config.WithRegion(providerData.GetRegion()))
apiClientConfigOptions = append(apiClientConfigOptions))

Since the KMS API already implemented the new multi-region concept, you don't need to set the region here (or better: the SDK should throw an error if you do 😄 ).

Apart from that, consider adding a unit tests for this func, see e.g. https://github.com/stackitcloud/terraform-provider-stackit/blob/8e776757ea2280d1222afe50c3024945b4d99eed/stackit/internal/services/git/utils/util_test.go

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Jul 24, 2025
@rubenhoenle rubenhoenle removed the Stale PR is marked as stale due to inactivity. label Jul 24, 2025
rubenhoenle added a commit to stackitcloud/stackit-sdk-go that referenced this pull request Jul 29, 2025
rubenhoenle added a commit to stackitcloud/stackit-sdk-go that referenced this pull request Aug 1, 2025
rubenhoenle added a commit to stackitcloud/stackit-sdk-go that referenced this pull request Aug 1, 2025
Copy link

github-actions bot commented Aug 5, 2025

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@ruslan-18 ruslan-18 marked this pull request as ready for review August 8, 2025 13:14
@ruslan-18 ruslan-18 requested a review from a team as a code owner August 8, 2025 13:14
@ruslan-18
Copy link
Author

@fsandel fyi

Copy link

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Aug 16, 2025
@marceljk marceljk removed the Stale PR is marked as stale due to inactivity. label Aug 17, 2025
Copy link

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions bot added Stale PR is marked as stale due to inactivity. and removed Stale PR is marked as stale due to inactivity. labels Aug 25, 2025
Copy link

github-actions bot commented Sep 4, 2025

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Sep 4, 2025
@marceljk marceljk removed the Stale PR is marked as stale due to inactivity. label Sep 5, 2025
Copy link

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Sep 13, 2025
@rubenhoenle
Copy link
Member

@fsandel Could you please resolve the conflicts?

@rubenhoenle rubenhoenle added has internal tracking issue and removed Stale PR is marked as stale due to inactivity. labels Sep 15, 2025
# stackit_kms_key (Data Source)

KMS Key resource schema. Must have a `region` specified in the provider configuration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all three data sources the examples are missing. Please add them in examples/data-sources/<data-source-name>/data-source.tf like you did it for the resources

Comment on lines +2 to +9
algorithm = "example algorithm"
backend = "software"
description = "new descr"
display_name = "example name"
import_only = false
key_ring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
purpose = "example purpose"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually have the project_id and depending ids, like in this case key_ring_id at the top of the example. And for the basic example we only set the required fields.

Suggested change
algorithm = "example algorithm"
backend = "software"
description = "new descr"
display_name = "example name"
import_only = false
key_ring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
purpose = "example purpose"
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
key_ring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
algorithm = "example algorithm"
backend = "software"
description = "example description"
display_name = "example name"
purpose = "example purpose"

If you want you can also add an additional example, where the stackit_kms_key resource is used together with stackit_kms_key_ring, but this is not necessary. If you add it, please add a comment to indicate, that it's a different example

- `algorithm` (String) The encryption algorithm that the key will use to encrypt data
- `backend` (String) The backend that is used for KMS. Right now, only software is accepted.
- `display_name` (String) The display name to distinguish multiple keys
- `import_only` (Boolean) Terraform's internal resource ID. It is structured as "`project_id`,`instance_id`".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description of import_only doesn't fit here. And based on the api spec, it's only an optional field

- `purpose` (String) The purpose for which the key will be used

### Optional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the api spec access_scope is missing

### Required

- `algorithm` (String) The encryption algorithm that the key will use to encrypt data
- `backend` (String) The backend that is used for KMS. Right now, only software is accepted.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with the migration from v1beta -> v1, this was renamed to protection

key_ring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
purpose = "example purpose"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an example how the resource can be imported, like we have it here

# Only use the import statement, if you want to import an existing ske cluster
import {
to = stackit_ske_cluster.import-example
id = "${var.project_id},${var.region},${var.ske_name}"
}

Comment on lines +2 to +6
description = "example description"
display_name = "example name"
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
region_id = "eu01"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change also the order here, so that project_id is first and remove region_id. Also add an import example

Suggested change
description = "example description"
display_name = "example name"
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
region_id = "eu01"
}
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
description = "example description"
display_name = "example name"
}

Comment on lines +2 to +8
algorithm = "example algorithm"
backend = "software"
description = "new descr"
display_name = "example name"
key_ring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
purpose = "example purpose"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the order, so that project_id and key_ring_id are first. And add an import example

Suggested change
algorithm = "example algorithm"
backend = "software"
description = "new descr"
display_name = "example name"
key_ring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
purpose = "example purpose"
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
key_ring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
algorithm = "example algorithm"
backend = "software"
description = "new descr"
display_name = "example name"
purpose = "example purpose"

github.com/stackitcloud/stackit-sdk-go/services/git v0.7.1
github.com/stackitcloud/stackit-sdk-go/services/iaas v0.28.0
github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.21-alpha
github.com/stackitcloud/stackit-sdk-go/services/kms v0.5.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably our fault that this is quite old, but this can be update to v1.0.0. You should then get the change for backend -> protection and the new field access_scope.

Please try to avoid upgrading other modules than the one that are required for you PR. I think most of them should be already in our main branch, so a rebase would probably fix this :)

)

var (
_ datasource.DataSource = &keyRingDataSource{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a nitpick and most of our datasources are also missing this. But this ensures that the Configure method is implemented correct

Suggested change
_ datasource.DataSource = &keyRingDataSource{}
_ datasource.DataSource = &keyRingDataSource{}
_ datasource.DataSourceWithConfigure = &instanceDataSource{}

@ruslan-18 ruslan-18 marked this pull request as draft September 17, 2025 14:33
Config: fmt.Sprintf("%s\n%s", testutil.KMSProviderConfig(), resourceKeyRingMinConfig),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.stackit_kms_key_ring.key_ring", "project_id", testutil.ConvertConfigVariable(testConfigKeyRingVarsMin["project_id"])),
resource.TestCheckResourceAttrPair(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also check the region and project_id this way btw (even if you don't set them manually in the Min test and use the fallback values from the provider config instead) to make sure the datasource and the resource return the same values

var (
_ resource.Resource = &wrappingKeyResource{}
_ resource.ResourceWithConfigure = &wrappingKeyResource{}
_ resource.ResourceWithImportState = &wrappingKeyResource{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add resource.ResourceWithModifyPlan here.

_ resource.ResourceWithModifyPlan = &userResource{}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then make sure to implement ModifyPlan properly so the region field works properly in case the default_region in the provider configuration is updated.

// ModifyPlan implements resource.ResourceWithModifyPlan.
// Use the modifier to set the effective region in the current plan.
func (r *userResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // nolint:gocritic // function signature required by Terraform
var configModel Model
// skip initial empty configuration to avoid follow-up errors
if req.Config.Raw.IsNull() {
return
}
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
if resp.Diagnostics.HasError() {
return
}
var planModel Model
resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...)
if resp.Diagnostics.HasError() {
return
}
utils.AdaptRegion(ctx, configModel.Region, &planModel.Region, r.providerData.GetRegion(), resp)
if resp.Diagnostics.HasError() {
return
}
resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...)
if resp.Diagnostics.HasError() {
return
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also make sure to do this for all of your resources within this PR 😊

Copy link

github-actions bot commented Oct 3, 2025

This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has internal tracking issue Stale PR is marked as stale due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants